package com.fauks.restful.controller;

import com.fauks.restful.bean.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AppController {

    @RequestMapping(path = "/api/sms")
    public SmsWrapper getSmsList() {
        List<SmsWrapper.SmsBean> smsList = new ArrayList<>();
        smsList.add(new SmsWrapper.SmsBean("爱情", "爱情爱情爱情爱情爱情爱情爱情爱情", 4));
        smsList.add(new SmsWrapper.SmsBean("祝福", "祝福祝福祝福祝福祝福祝福祝福祝福", 4));
        smsList.add(new SmsWrapper.SmsBean("亲情", "亲情亲情亲情亲情亲情亲情亲情亲情", 3));
        smsList.add(new SmsWrapper.SmsBean("老师", "老师老师老师老师老师老师老师老师", 4));
        smsList.add(new SmsWrapper.SmsBean("同学好", "同学好同学好同学好同学好同学好同学好", 4));
        return new SmsWrapper(smsList.size(), smsList, 200, "");
    }

    @RequestMapping("/api/register")
    public ApiResult register(String username, String password) {

        /*ApiUser.username = username;
        ApiUser.password = password;*/
        System.out.println("username=" + username + ",password=" + password);
        ApiResult apiResult = new ApiResult();
        if (!"1".equals(username)) {
            apiResult.code = 0;
            apiResult.message = "网络错误";
        } else {
            apiResult.code = 1;
            apiResult.message = "注册成功";
        }
        return apiResult;
    }

    @RequestMapping("/api/login")
    public ApiResult login(String username, String password) {
        ApiResult apiResult = new ApiResult();
        if (!"1".equals(username)) {
            apiResult.code = 0;
            apiResult.message = "网络错误";
        } else {
            apiResult.code = 1;
            apiResult.message = "登录成功";
        }
        return apiResult;
    }

    @RequestMapping("/api/userInfo")
    public UserInfo userInfo() {
        return new UserInfo("fauks", 12);
    }

    @RequestMapping("api/jsonArray")
    public ApiResult<List<ApiUser>> getJsonArray() {
        ApiResult<List<ApiUser>> user = new ApiResult<>();
        user.code = 1;
        user.message = "success";

        List<ApiUser> apiUserList = new ArrayList<>();
       /* apiUserList.add(new ApiUser("1", "fauks"));
        apiUserList.add(new ApiUser("2", "bob"));
        apiUserList.add(new ApiUser("3", "jay"));*/
        user.data = apiUserList;
        return user;
    }

    @RequestMapping("api/jsonObj")
    public ApiResult<ApiUser> getJsonObj() {
        ApiResult<ApiUser> user = new ApiResult<>();
        user.code = 1;
        user.message = "success";
        ApiUser apiUser = new ApiUser();
        apiUser.password = "12";
        apiUser.username = "fauks";
        user.data = apiUser;
        return user;
    }

    @RequestMapping("api/obj")
    public ApiUser getObj(String[] strings) {
        System.out.println("===>" + strings);
        ApiUser apiUser = new ApiUser();
        apiUser.password = "12";
        apiUser.username = "asdfasdf";
        return apiUser;
    }

    @RequestMapping("api/params1")
    public ApiUser params1(String[] strings) {
        for (String string : strings) {
            System.out.println(string);
        }
        ApiUser apiUser = new ApiUser();
        return apiUser;
    }

    @RequestMapping("api/list")
    public List<ApiUser> getList() {
        List<ApiUser> apiUserList = new ArrayList<>();
        apiUserList.add(new ApiUser("1", "fauks", "http://192.168.3.11:9900/1.jpg"));
        apiUserList.add(new ApiUser("2", "bob", "http://192.168.3.11:9900/2.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/3.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/4.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/5.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/6.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/7.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/8.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/9.jpg"));
        apiUserList.add(new ApiUser("3", "jay", "http://192.168.3.11:9900/10.jpg"));
        return apiUserList;
    }

    @RequestMapping("api/void")
    public ApiResult getVoid() {
        ApiResult apiResult = new ApiResult();
        apiResult.code = 1;
        apiResult.message = "操作成功";
        return apiResult;
    }
}
